package ldh.im.base.handler;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;
import ldh.im.dto.base.Dto;
import ldh.im.TransferData;

import java.util.List;

@ChannelHandler.Sharable
public class ToCoderHandler extends MessageToMessageCodec<TransferData, Dto> {

    @Override
    protected void encode(ChannelHandlerContext ctx, Dto msg, List<Object> out) throws Exception {
        TransferData transferData = new TransferData();
        transferData.setData(msg);
        out.add(transferData);
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, TransferData msg, List<Object> out) throws Exception {
        out.add(msg.getData());
    }
}
